<!--$Id: naming.so,v 10.51 2007/09/26 15:11:31 bostic Exp $-->
<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: File naming</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><b><dl><dt>Berkeley DB Reference Guide:<dd>Environment</dl></b></td>
<td align=right><a href="../env/db_config.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../env/region.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p align=center><b>File naming</b></p>
<p>One of the most important tasks of the database environment is to
structure file naming within Berkeley DB.  Cooperating applications (or
multiple invocations of the same application) must agree on the location
of the database environment, log files and other files used by the Berkeley DB
subsystems, and, of course, the database files.  Although it is possible
to specify full pathnames to all Berkeley DB methods, this is cumbersome and
requires applications be recompiled when database files are moved.</p>
<p>Applications are normally expected to specify a single directory home
for the database environment.  This can be done easily in the call to
<a href="../../api_c/env_open.html">DB_ENV-&gt;open</a> by specifying a value for the <b>db_home</b>
argument.  There are more complex configurations in which it may be
desirable to override <b>db_home</b> or provide supplementary path
information.</p>
<b>Specifying file naming to Berkeley DB</b>
<p>The following list describes the possible ways in which file naming
information may be specified to the Berkeley DB library.  The specific
circumstances and order in which these ways are applied are described
in a subsequent paragraph.</p>
<br>
<b><a name="db_home">db_home</a></b><ul compact><li>If the <b>db_home</b> argument to <a href="../../api_c/env_open.html">DB_ENV-&gt;open</a> is non-NULL,
its value may be used as the database home, and files named relative to
its path.</ul>
<b><a name="DB_HOME">DB_HOME</a></b><ul compact><li>If the DB_HOME environment variable is set when <a href="../../api_c/env_open.html">DB_ENV-&gt;open</a> is
called, its value may be used as the database home, and files named
relative to its path.
<p>The DB_HOME environment variable is intended to permit users and system
administrators to override application and installation defaults.  For
example::</p>
<blockquote><pre>env DB_HOME=/database/my_home application</pre></blockquote>
<p>Application writers are encouraged to support the <b>-h</b> option
found in the supporting Berkeley DB utilities to let users specify a database
home.</p></ul>
<b><a href="../../api_c/env_class.html">DB_ENV</a> methods</b><ul compact><li>There are three <a href="../../api_c/env_class.html">DB_ENV</a> methods that affect file naming.  The
<a href="../../api_c/env_set_data_dir.html">DB_ENV-&gt;set_data_dir</a> method specifies a directory to search for database
files.  The <a href="../../api_c/env_set_lg_dir.html">DB_ENV-&gt;set_lg_dir</a> method specifies a directory in which to
create logging files.  The <a href="../../api_c/env_set_tmp_dir.html">DB_ENV-&gt;set_tmp_dir</a> method specifies a
directory in which to create backing temporary files.  These methods
are intended to permit applications to customize a file location for a
database.  For example, an application writer can place data files and
log files in different directories or instantiate a new log directory
each time the application runs.</ul>
<b><a href="../../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a></b><ul compact><li>The same information specified to the <a href="../../api_c/env_class.html">DB_ENV</a> methods may also be
specified using the <a href="../../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration file.</ul>
<br>
<b>Filename resolution in Berkeley DB</b>
<p>The following list describes the specific circumstances and order in
which the different ways of specifying file naming information are
applied.  Berkeley DB filename processing proceeds sequentially through the
following steps:</p>
<br>
<b>absolute pathnames</b><ul compact><li>If the filename specified to a Berkeley DB function is an <i>absolute
pathname</i>, that filename is used without modification by Berkeley DB.
<p>On UNIX systems, an absolute pathname is defined as any pathname that
begins with a leading slash (<b>/</b>).</p>
<p>On Windows systems, an absolute pathname is any pathname that begins with
a leading slash or leading backslash (<b>\</b>); or any
pathname beginning with a single alphabetic character, a colon and a
leading slash or backslash (for example, <b>C:/tmp</b>).</p></ul>
<b><a href="../../api_c/env_class.html">DB_ENV</a> methods, DB_CONFIG</b><ul compact><li>If a relevant configuration string (for example, set_data_dir), is
specified either by calling a <a href="../../api_c/env_class.html">DB_ENV</a> method or as a line in the
<a href="../../ref/env/db_config.html#DB_CONFIG">DB_CONFIG</a> configuration file, the value is prepended to the
filename.  If the resulting filename is an absolute pathname, the
filename is used without further modification by Berkeley DB.</ul>
<b>db_home</b><ul compact><li>If the application specified a non-NULL <b>db_home</b> argument to
<a href="../../api_c/env_open.html">DB_ENV-&gt;open</a>, its value is prepended to the filename.  If the
resulting filename is an absolute pathname, the filename is used without
further modification by Berkeley DB.</ul>
<b>DB_HOME</b><ul compact><li>If the <b>db_home</b> argument is NULL, the DB_HOME environment
variable was set, and the application has set the appropriate
<a href="../../api_c/env_open.html#DB_USE_ENVIRON">DB_USE_ENVIRON</a> or <a href="../../api_c/env_open.html#DB_USE_ENVIRON_ROOT">DB_USE_ENVIRON_ROOT</a> flags, its value
is prepended to the filename.  If the resulting filename is an absolute
pathname, the filename is used without further modification by Berkeley DB.</ul>
<b>default</b><ul compact><li>Finally, all filenames are interpreted relative to the current working
directory of the process.</ul>
<br>
<p>The common model for a Berkeley DB environment is one in which only the DB_HOME
environment variable, or the <b>db_home</b> argument is specified.  In
this case, all data filenames are relative to that directory, and all
files created by the Berkeley DB subsystems will be created in that directory.</p>
<p>The more complex model for a transaction environment might be one in
which a database home is specified, using either the DB_HOME environment
variable or the <b>db_home</b> argument to <a href="../../api_c/env_open.html">DB_ENV-&gt;open</a>; and then
the data directory and logging directory are set to the relative
pathnames of directories underneath the environment home.</p>
<b>Examples</b>
<p>Store all files in the directory <b>/a/database</b>:</p>
<blockquote><pre>dbenv-&gt;open(dbenv, "/a/database", flags, mode);</pre></blockquote>
<p>Create temporary backing files in <b>/b/temporary</b>, and all other files
in <b>/a/database</b>:</p>
<blockquote><pre>dbenv-&gt;set_tmp_dir(dbenv, "/b/temporary");
dbenv-&gt;open(dbenv, "/a/database", flags, mode);</pre></blockquote>
<p>Store data files in <b>/a/database/datadir</b>, log files in
<b>/a/database/logdir</b>, and all other files in the directory
<b>/a/database</b>:</p>
<blockquote><pre>dbenv-&gt;set_lg_dir(dbenv, "logdir");
dbenv-&gt;set_data_dir(dbenv, "datadir");
dbenv-&gt;open(dbenv, "/a/database", flags, mode);</pre></blockquote>
<p>Store data files in <b>/a/database/data1</b> and <b>/b/data2</b>, and
all other files in the directory <b>/a/database</b>.  Any data files
that are created will be created in <b>/b/data2</b>, because it is
the first data file directory specified:</p>
<blockquote><pre>dbenv-&gt;set_data_dir(dbenv, "/b/data2");
dbenv-&gt;set_data_dir(dbenv, "data1");
dbenv-&gt;open(dbenv, "/a/database", flags, mode);</pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../env/db_config.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../env/region.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</body>
</html>
